package com.samsungimaging.asphodel.multimedia;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.view.SurfaceHolder;
import com.samsung.app.Logger;

class FFmpegScreen
{
  private static final int SCREEN_TYPE_NUM = 4;
  private static final String TAG = "[FFmpegScreen]";
  private Bitmap[] m_background = null;
  private Canvas m_canvas = null;
  private int m_curCameraRotate = 0;
  private int m_curScreenType = 0;
  private Matrix m_matrix = null;
  private int[][] m_screenPositoin = null;
  private int[][] m_screenSize = null;
  private SurfaceHolder m_surfaceHolder = null;

  public FFmpegScreen(Bitmap paramBitmap1, Bitmap paramBitmap2, int[][] paramArrayOfInt1, int[][] paramArrayOfInt2, int paramInt1, int paramInt2)
  {
    this.m_background[0] = paramBitmap1;
    this.m_background[1] = paramBitmap2;
    this.m_screenPositoin = new int[4][];
    this.m_screenSize = new int[4][];
    for (int i = 0; ; i++)
    {
      if (i >= 4)
      {
        changeScreenConfig(paramInt1, paramInt2);
        return;
      }
      this.m_screenPositoin[i] = new int[2];
      if (paramArrayOfInt1 != null)
      {
        this.m_screenPositoin[i][0] = paramArrayOfInt1[i][0];
        this.m_screenPositoin[i][1] = paramArrayOfInt1[i][1];
      }
      this.m_screenSize[i] = new int[2];
      if (paramArrayOfInt2 == null)
        continue;
      this.m_screenSize[i][0] = paramArrayOfInt2[i][0];
      this.m_screenSize[i][1] = paramArrayOfInt2[i][1];
    }
  }

  public int changeScreenConfig(int paramInt1, int paramInt2)
  {
    this.m_curScreenType = paramInt1;
    this.m_curCameraRotate = paramInt2;
    return 0;
  }

  public void configureSurface(FFmpegJNI.Command paramCommand, SurfaceHolder paramSurfaceHolder)
  {
    switch (paramCommand.ordinal())
    {
    
    case 5:
    	this.m_surfaceHolder = paramSurfaceHolder;
    	break;
    case 7:
    	this.m_surfaceHolder = paramSurfaceHolder;
    	break;
    case 6:
    	this.m_surfaceHolder = paramSurfaceHolder;
    	break;
    default:
        Logger.e("[FFmpegScreen]", "Unknown Command!");
    }
    
  }

  public int drawScreen(Bitmap paramBitmap)
  {
    int i = 0;
    int j = 0;
    Bitmap localBitmap = null;
    if (!Thread.currentThread().isInterrupted()){
    	 synchronized (this.m_surfaceHolder)
         {
           this.m_canvas = this.m_surfaceHolder.lockCanvas();
           if (this.m_canvas == null){
             return -1;
           }
      switch (this.m_curCameraRotate)
      {

      case 0:
      case 180:
    	  i = paramBitmap.getWidth();
          j = paramBitmap.getHeight();
          break;
      case 90:
    	  i = paramBitmap.getHeight();
          j = paramBitmap.getWidth();
      case 270:
      default:
          this.m_matrix.reset();
          if (this.m_curCameraRotate != 0)
            this.m_matrix.postRotate(this.m_curCameraRotate, paramBitmap.getWidth() / 2.0F, paramBitmap.getHeight() / 2.0F);
          this.m_matrix.postScale(this.m_screenSize[this.m_curScreenType][0] / i, this.m_screenSize[this.m_curScreenType][1] / j);
          localBitmap = Bitmap.createBitmap(paramBitmap, 0, 0, paramBitmap.getWidth(), paramBitmap.getHeight(), this.m_matrix, true);
      }
      this.m_canvas.drawBitmap(this.m_background[(this.m_curScreenType % 2)], 0.0F, 0.0F, null);
      this.m_canvas.drawBitmap(localBitmap, this.m_screenPositoin[this.m_curScreenType][0], this.m_screenPositoin[this.m_curScreenType][1], null);
      this.m_surfaceHolder.unlockCanvasAndPost(this.m_canvas);
      return 0;
    }
    	 
  }
    return -1;
}
}